package com.crm.system.controller.index;


import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.index.NewsQO;
import com.crm.model.qo.index.NotifyQO;
import com.crm.model.vo.announcement.AnnouncementVO;
import com.crm.model.vo.announcement.NewsVO;
import com.crm.model.vo.index.PerformanceVO;
import com.crm.model.vo.index.ProductVO;
import com.crm.model.vo.opportunityManager.PerformanceRankingVO;
import com.crm.system.service.index.FirstPageService;
import com.crm.system.service.index.NewsService;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 首页信息
 * @author baijian
 * @date 2021/04/25 10:10
 */
@RestController
@RequestMapping("/firstPageController")
public class FirstPageController {

    @Autowired
    private FirstPageService firstPageService;

    /**
     * 首页统计信息
     * @param dateType thisMonth 本月 thisLastMonth 上月 thisYear 本年
     * @param bs 1数据一览  2销售简报
     * @return
     */
    @PostMapping("/firstPageContent")
    public DataResponse firstPageContent(@RequestParam(value = "dateType", required = true) String dateType,
                                         @RequestParam(value = "bs", required = true) String bs){
        Map<String,Object> map = firstPageService.firstPageContent(dateType,bs);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
    }

    /**
     * 首页统计业绩排行榜
     * @param dateType 1年 2年月
     * @param
     * @return
     */
    @PostMapping("/personalPerformanceRanking")
    public DataResponse personalPerformanceRanking(@RequestParam(value = "dateType", required = true) String dateType,
                                                   @RequestParam(value = "combination", required = true) String combination){
        //Map<String,Object> map = firstPageService.personalPerformanceRankingRedis(dateType,combination);

        Map<String,Object> map = firstPageService.personalPerformanceRankingList(dateType,combination);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
    }

    /**
     * 首页统计业绩排行榜
     * @param dateType 1年 2年月
     * @param
     * @return
     */
    /*@PostMapping("/performanceRanking")
    public DataResponse performanceRanking(@RequestParam(value = "dateType", required = true) String dateType,
                                                   @RequestParam(value = "combination", required = true) String combination){
        String ranking = firstPageService.personalPerformanceRanking(dateType,combination);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),ranking);
    }*/



    /**
     * 首页统计个人业绩走势图
     * @return
     */
    @PostMapping("/performanceTrend")
    public DataResponse performanceTrend(){
        PerformanceVO performanceVO = firstPageService.performanceTrend();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),performanceVO);
    }

    /**
     * 产品成交排行榜
     * @param dateType 1年 2年月
     * @param combination dateType 1 2021  2 202101
     * @return
     */
    @PostMapping("/productTurnoverList")
    public DataResponse productTurnoverList(@RequestParam(value = "dateType", required = true) String dateType,
                                            @RequestParam(value = "combination", required = true) String combination){
        List<ProductVO> list = firstPageService.productTurnoverList(dateType,combination);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }

    /**
     * 二级管理首页统计信息
     * @param dateType thisWeek 本周 lastWeek 上周 lastMonth 上月 thisMonth 本月
     * @return
     */
    @PostMapping("/adminFirstPageContent")
    public DataResponse adminFirstPageContent(@RequestParam(value = "dateType", required = true) String dateType){
        Map<String,Object> map = firstPageService.adminFirstPageContent(dateType);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
    }

    /**
     * 二级管理首页统计信息
     * @param yearMonth yyyy-MM
     * @return
     */
    @PostMapping("/userFirstPageContent")
    public DataResponse userFirstPageContent(@RequestParam(value = "yearMonth", required = true) String yearMonth){
        Map<String,Object> map = firstPageService.userFirstPageContent(yearMonth);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),map);
    }

    /**
     * 首页统计二级管理个人业绩金额走势图
     * @return
     */
    @PostMapping("/adminPerformanceTrend")
    public DataResponse adminPerformanceTrend(){
        PerformanceVO performanceVO = firstPageService.adminPerformanceTrend();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),performanceVO);
    }

    /**
     * 首页统计二级管理全国公司业绩排行榜
     * @param dateType thisMonth 本月 lastMonth 上月   thisYear 今年  lastYear 去年
     * @return
     */
    @PostMapping("/adminCompanyPerformanceRanking")
    public DataResponse adminCompanyPerformanceRanking(@RequestParam(value = "dateType", required = true) String dateType){
        List<PerformanceRankingVO> list = firstPageService.adminCompanyPerformanceRanking(dateType);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }

    /**
     * 首页统计二级管理分公司下的业绩排行榜
     * @param dateType thisMonth 本月 lastMonth 上月   thisYear 今年  lastYear 去年 thisWeek 本周  lastWeek 上周
     * @return
     */
    @PostMapping("/adminCompanyPersonalPerformanceRanking")
    public DataResponse adminCompanyPersonalPerformanceRanking(@RequestParam(value = "dateType", required = true) String dateType){
        List<PerformanceRankingVO> list = firstPageService.adminCompanyPersonalPerformanceRanking(dateType);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }

    /**
     * 首页统计二级管理分公司下的业绩排行榜
     * @param dateType thisMonth 本月 lastMonth 上月   thisYear 今年  lastYear 去年 thisWeek 本周  lastWeek 上周
     * @return
     */
    @PostMapping("/adminCompanyPersonalPerformanceRank")
    public DataResponse adminCompanyPersonalPerformanceRank(@RequestParam(value = "dateType", required = true) String dateType,
                                                            @RequestParam(value = "seniority", required = true) String  seniority
                                                            ){
        List<PerformanceRankingVO> list = firstPageService.adminCompanyPersonalPerformanceRank(dateType,seniority);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }

    /**
     * 查询所有入职区间数据
     */
    @GetMapping("/getSeniority")
    public DataResponse getSeniority(){
        List<String> list = firstPageService.getSeniority();
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }


}
